package C3P0;

import com.mchange.v2.c3p0.ComboPooledDataSource;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;

/**
 * 数据库连接池
 *
 * 注意添加mysql的jar包
 * @author Mc.Chai
 * @program: JavaWeb
 * @create 2021-12-15-22:06 22:06
 */
public class C3P0Demo {
    public static void main(String[] args) throws SQLException {
        //1.创建数据库连接池对象,没有参数使用默认配置
        DataSource dataSource=new ComboPooledDataSource();
        //通过参数指定连接池对象
        //DataSource dataSource=new ComboPooledDataSource("dumbTestConfig");//config.xml中<named-config name="dumbTestConfig">
        //2.获取连接对象
        Connection connection = dataSource.getConnection();
        System.out.println(connection);
    }
}
